package cn.sciento.transfer.api.dto;

import io.swagger.annotations.ApiModelProperty;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

public class DatasourceDTO {
  private static final String DATABASE_NAME = "${database_name}";
  
  @ApiModelProperty("表ID，主键")
  @Id
  @GeneratedValue
  private Long datasourceId;
  
  @ApiModelProperty("数据源编码")
  @NotBlank
  @Length(max = 30)
  private String datasourceCode;
  
  @ApiModelProperty("数据源名称")
  @Length(max = 600)
  @NotBlank
  private String description;
  
  @ApiModelProperty("数据源URL地址")
  @NotBlank
  @Length(max = 600)
  private String datasourceUrl;
  
  @ApiModelProperty("用户")
  @NotBlank
  @Length(max = 100)
  private String username;
  
  @ApiModelProperty("加密密码")
  @NotBlank
  @Length(max = 300)
  private String passwordEncrypted;
  
  @ApiModelProperty("是否启用，1启用、0禁用")
  @Range(max = 1L)
  private Integer enabledFlag;
  
  @NotBlank
  @Length(max = 30)
  private String dbType;
  
  @ApiModelProperty("数据库驱动类")
  @NotBlank
  private String driverClass;
  
  @ApiModelProperty("连接池类型，独立值集：HPFM.DB_POOL_TYPE")
  @NotBlank
  @Length(max = 30)
  private String dbPoolType;
  
  @ApiModelProperty("获取报表引擎查询器类名")
  @Length(max = 240)
  private String queryerClass;
  
  @ApiModelProperty("报表引擎查询器使用的数据源连接池类名")
  @Length(max = 240)
  private String poolClass;
  
  @ApiModelProperty("数据源配置选项(JSON格式）")
  private String options;
  
  @ApiModelProperty("备注")
  @Length(max = 240)
  private String remark;
  
  @ApiModelProperty("数据源用途，值集：HPFM.DATASOURCE_PURPOSE")
  private String dsPurposeCode;
  
  @ApiModelProperty("租户Id")
  private Long tenantId;
  
  @Transient
  private String dsPurposeCodeMeaning;
  
  @Transient
  private String tenantName;
  
  public String createConnectUrl(String initDBCode) {
    return this.datasourceUrl.replace("${database_name}", initDBCode + "?");
  }
  
  public Long getDatasourceId() {
    return this.datasourceId;
  }
  
  public void setDatasourceId(Long datasourceId) {
    this.datasourceId = datasourceId;
  }
  
  public String getDatasourceCode() {
    return this.datasourceCode;
  }
  
  public void setDatasourceCode(String datasourceCode) {
    this.datasourceCode = datasourceCode;
  }
  
  public String getDescription() {
    return this.description;
  }
  
  public void setDescription(String description) {
    this.description = description;
  }
  
  public String getDatasourceUrl() {
    return this.datasourceUrl;
  }
  
  public void setDatasourceUrl(String datasourceUrl) {
    this.datasourceUrl = datasourceUrl;
  }
  
  public String getUsername() {
    return this.username;
  }
  
  public void setUsername(String username) {
    this.username = username;
  }
  
  public String getPasswordEncrypted() {
    return this.passwordEncrypted;
  }
  
  public void setPasswordEncrypted(String passwordEncrypted) {
    this.passwordEncrypted = passwordEncrypted;
  }
  
  public Integer getEnabledFlag() {
    return this.enabledFlag;
  }
  
  public void setEnabledFlag(Integer enabledFlag) {
    this.enabledFlag = enabledFlag;
  }
  
  public String getDbType() {
    return this.dbType;
  }
  
  public void setDbType(String dbType) {
    this.dbType = dbType;
  }
  
  public String getDriverClass() {
    return this.driverClass;
  }
  
  public void setDriverClass(String driverClass) {
    this.driverClass = driverClass;
  }
  
  public String getDbPoolType() {
    return this.dbPoolType;
  }
  
  public void setDbPoolType(String dbPoolType) {
    this.dbPoolType = dbPoolType;
  }
  
  public String getQueryerClass() {
    return this.queryerClass;
  }
  
  public void setQueryerClass(String queryerClass) {
    this.queryerClass = queryerClass;
  }
  
  public String getPoolClass() {
    return this.poolClass;
  }
  
  public void setPoolClass(String poolClass) {
    this.poolClass = poolClass;
  }
  
  public String getOptions() {
    return this.options;
  }
  
  public void setOptions(String options) {
    this.options = options;
  }
  
  public String getRemark() {
    return this.remark;
  }
  
  public void setRemark(String remark) {
    this.remark = remark;
  }
  
  public String getDsPurposeCode() {
    return this.dsPurposeCode;
  }
  
  public void setDsPurposeCode(String dsPurposeCode) {
    this.dsPurposeCode = dsPurposeCode;
  }
  
  public String getDsPurposeCodeMeaning() {
    return this.dsPurposeCodeMeaning;
  }
  
  public void setDsPurposeCodeMeaning(String dsPurposeCodeMeaning) {
    this.dsPurposeCodeMeaning = dsPurposeCodeMeaning;
  }
  
  public Long getTenantId() {
    return this.tenantId;
  }
  
  public void setTenantId(Long tenantId) {
    this.tenantId = tenantId;
  }
  
  public String getTenantName() {
    return this.tenantName;
  }
  
  public void setTenantName(String tenantName) {
    this.tenantName = tenantName;
  }
}
